﻿<%@ Page Title="" Language="C#" MasterPageFile="~/MonitoringPlanSite.Master" AutoEventWireup="true" 
    CodeBehind="AddNewIndicatorToActivity.aspx.cs" MaintainScrollPositionOnPostback="true"
    Inherits="AmkeniCrossLoginApplication.Amkeni_Monitoring_Plan.AddNewIndicatorToActivity" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>

<%@ Register Assembly="CustomDropDownList" Namespace="CustomDropDownList" TagPrefix="ddl" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
    <script>
        function Validate_Indicator(sender, args) {
            var oi = document.getElementById("<%= IndicatorList.ClientID %> ").value;
            var pi = document.getElementById("<%= ProcessIndicatorTextBox.ClientID %>").value;
            args.IsValid = (oi.value != "N/A") || (pi.value != "");
        }
    </script>

    <asp:EntityDataSource ID="OutcomeDataSource" runat="server" ConnectionString="name=Amkeni_DatabaseEntities" 
        DefaultContainerName="Amkeni_DatabaseEntities" EnableFlattening="False" 
        EntitySetName="programme_outcome" Select="it.[outcome_id]"></asp:EntityDataSource>

    <asp:EntityDataSource ID="ImplementingPartnerDataSource" runat="server" ConnectionString="name=Amkeni_DatabaseEntities"
        DefaultContainerName="Amkeni_DatabaseEntities" EnableFlattening="False"
        EntitySetName="implementing_partner" Select="it.[ip_id], it.[name], it.[abbreviation]">
    </asp:EntityDataSource>

    <asp:EntityDataSource ID="RFPDataSource" runat="server" ConnectionString="name=Amkeni_DatabaseEntities" 
        DefaultContainerName="Amkeni_DatabaseEntities" EnableFlattening="False" EntitySetName="RFPs" 
        EntityTypeFilter="RFP" Select="it.[RFP_id], it.[RFP_name]"></asp:EntityDataSource>

    <asp:EntityDataSource ID="YearDataSource" runat="server" ConnectionString="name=Amkeni_DatabaseEntities" 
        DefaultContainerName="Amkeni_DatabaseEntities" EnableFlattening="False" EntitySetName="years" 
        EntityTypeFilter="year" Select="it.[year_id], it.[year1]"></asp:EntityDataSource>

    <asp:EntityDataSource ID="ActivityDataSource" runat="server" ConnectionString="name=Amkeni_DatabaseEntities" 
        DefaultContainerName="Amkeni_DatabaseEntities" EnableDelete="True" EnableFlattening="False" 
        EnableInsert="True" EnableUpdate="True" EntitySetName="monitoring_plan" AutoGenerateWhereClause="true" 
        EntityTypeFilter="monitoring_plan" Include="implementing_partner,RFP,year"></asp:EntityDataSource>

    <asp:DetailsView ID="ActivityDetailsView" runat="server" DataSourceID="ActivityDataSource"
        AutoGenerateRows="False" DataKeyNames="monitoring_plan_id" OnItemDeleted="ActivityDetailsView_ItemDeleted"
        CssClass="NewGrid">
        <AlternatingRowStyle CssClass="NewGridAlt" />
        <Fields>
            <asp:TemplateField HeaderText="Implementing Partner" SortExpression="ip_id">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataTextField="abbreviation" DataValueField="ip_id" DataSourceID="ImplementingPartnerDataSource"
                        SelectedValue='<%# Eval("implementing_partner.ip_id") %>'>
                    </asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList1" runat="server"
                        DataTextField="abbreviation" DataValueField="ip_id" DataSourceID="ImplementingPartnerDataSource">
                    </asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("implementing_partner.name") %>' ID="Label2"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Call for Proposal" SortExpression="RFP_id">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="RFPDataSource" 
                        DataTextField="RFP_name" DataValueField="RFP_id" SelectedValue='<%# Eval("RFP.RFP_id") %>'></asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="RFPDataSource" 
                        DataTextField="RFP_name" DataValueField="RFP_id"></asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("RFP.RFP_name") %>' ID="Label3"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Year" SortExpression="year_id">
                <EditItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="YearDataSource" 
                        DataTextField="year1" DataValueField="year_id" SelectedValue='<%# Eval("year.year_id") %>'></asp:DropDownList>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:DropDownList ID="DropDownList3" runat="server" DataSourceID="YearDataSource" 
                        DataTextField="year1" DataValueField="year_id"></asp:DropDownList>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("year.year1") %>' ID="Label7"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Activity" SortExpression="activity">
                <EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("activity") %>' ID="TextBox7"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("activity") %>' ID="TextBox8"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("activity") %>' ID="Label8"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Programme Officer" SortExpression="programme_officer">
                <EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("programme_officer") %>' ID="TextBox8"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("programme_officer") %>' ID="TextBox9"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("programme_officer") %>' ID="Label9"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="IP Officer" SortExpression="ip_officer">
                <EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("ip_officer") %>' ID="TextBox9"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("ip_officer") %>' ID="TextBox10"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("ip_officer") %>' ID="Label10"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Resource Required" SortExpression="resource_required">
                <EditItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("resource_required") %>' ID="TextBox10"></asp:TextBox>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <asp:TextBox runat="server" Text='<%# Bind("resource_required") %>' ID="TextBox11"></asp:TextBox>
                </InsertItemTemplate>
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Bind("resource_required") %>' ID="Label11"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" ButtonType="Button"></asp:CommandField>
        </Fields>
        <FooterStyle CssClass="NewGridFooter" />
    </asp:DetailsView>

    <br />
    <asp:EntityDataSource ID="IndicatorDataSource" runat="server" ConnectionString="name=Amkeni_DatabaseEntities" 
        DefaultContainerName="Amkeni_DatabaseEntities" EnableDelete="True" EnableFlattening="False" 
        EnableInsert="True" EnableUpdate="True" EntitySetName="activity_indicator_connector" Include="indicator"
        AutoGenerateWhereClause="true">
    </asp:EntityDataSource>
    <asp:GridView ID="IndicatorGridView" runat="server" DataSourceID="IndicatorDataSource" ShowFooter="true" ShowHeader="true" 
        AutoGenerateColumns="False" DataKeyNames="activity_indicator_connector_id" CssClass="NewGrid">
        <AlternatingRowStyle CssClass="NewGridAlt" />
        <Columns>
            <asp:TemplateField HeaderText="Indicator" SortExpression="indicator_id">
                <ItemTemplate>
                    <asp:Label runat="server" Text='<%# Eval("indicator.name") %>' ID="Label1"></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
            <asp:CommandField ShowDeleteButton="True" ButtonType="Button"></asp:CommandField>
        </Columns>
        <FooterStyle CssClass="NewGridFooter" />
    </asp:GridView>

    <br />

    <asp:Label ID="MsgLabel" runat="server">Add an indicator to the Activity above</asp:Label>
                <br />
                <asp:Table ID="Table2" runat="server" GridLines="Both" CssClass="NewGrid">
                    <asp:TableRow>
                    <asp:TableCell>
                        <asp:Label ID="Label7" runat="server" Text="Outcome"></asp:Label>
                    </asp:TableCell>
                    <asp:TableCell>
                        <ddl:CustomDropDownList ID="OutcomeList" runat="server" DataSourceID="OutcomeDataSource" 
                            DataTextField="outcome_id" DataValueField="outcome_id" AutoPostBack="True"
                            OnSelectedIndexChanged="OutcomeList_SelectedIndexChanged"
                            OnDataBound="OutcomeList_DataBound">
                        </ddl:CustomDropDownList>
                        &nbsp;&nbsp;
                        <asp:Label ID="OutcomeLabel" runat="server"></asp:Label>
                        &nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="V3" runat="server" ErrorMessage="*" ForeColor="Red"
                            ControlToValidate="OutcomeList" InitialValue="N/A" ValidationGroup="_plan" SetFocusOnError="true"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                        <asp:Label ID="Label3" runat="server" Text="Output"></asp:Label>
                    </asp:TableCell>
                    <asp:TableCell>
                        <ddl:CustomDropDownList ID="OutputList" runat="server" 
                            DataTextField="output_id" DataValueField="output_id" AutoPostBack="true" 
                            OnSelectedIndexChanged="OutputList_SelectedIndexChanged" AppendDataBoundItems="false"
                            OnDataBound="OutputList_DataBound">
                            <asp:ListItem Selected="True" Text="N/A" Value="N/A" ></asp:ListItem>
                        </ddl:CustomDropDownList>
                        &nbsp;&nbsp;
                        <asp:Label ID="OutputLabel" runat="server"></asp:Label>
                        &nbsp;&nbsp;
                        <asp:RequiredFieldValidator ID="V4" runat="server" ErrorMessage="*" ForeColor="Red"
                            ControlToValidate="OutputList" InitialValue="N/A" ValidationGroup="_plan" SetFocusOnError="true"></asp:RequiredFieldValidator>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                        <asp:Label ID="Label5" runat="server" Text="Output Indicator"></asp:Label>
                    </asp:TableCell>
                    <asp:TableCell>
                        <ddl:CustomDropDownList ID="IndicatorList" runat="server" DataTextField="output_indicator_id"
                            DataValueField="indicator_id" AppendDataBoundItems="false" AutoPostBack="true"
                            OnDataBound="IndicatorList_DataBound" OnSelectedIndexChanged="IndicatorList_SelectedIndexChanged">
                            <asp:ListItem Selected="True" Text="N/A" Value="N/A" ></asp:ListItem>
                        </ddl:CustomDropDownList>
                        &nbsp;&nbsp;
                        <asp:Label ID="IndicatorLabel" runat="server" />
                        &nbsp;&nbsp;
                        <%--<asp:RequiredFieldValidator ID="V6" runat="server" ErrorMessage="*" ForeColor="Red"
                            ControlToValidate="IndicatorList" InitialValue="N/A" ValidationGroup="plan">
                        </asp:RequiredFieldValidator>--%>
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell>
                        <asp:Label ID="Label1" runat="server" Text="Process Indicator"></asp:Label>
                    </asp:TableCell>
                    <asp:TableCell>
                        <asp:TextBox ID="ProcessIndicatorTextBox" runat="server" Width="50%" 
                            AutoPostBack="true" OnTextChanged="ProcessIndicatorTextBox_TextChanged">
                        </asp:TextBox>
                        <asp:AutoCompleteExtender ID="AutoCompleteExtender1" runat="server" 
                            TargetControlID="ProcessIndicatorTextBox"
                            ServiceMethod="AutoCompleteAjaxRequest"
                            ServicePath="~/Amkeni_Monitoring_Plan/Classes/AutoComplete.asmx"
                            MinimumPrefixLength="2"
                            CompletionInterval="100"
                            EnableCaching="false"
                            CompletionSetCount="10"
                            FirstRowSelected="false">
                        </asp:AutoCompleteExtender>
                        <asp:HiddenField ID="ProcessIndicatorIdHiddenField" runat="server" />
                    </asp:TableCell>
                </asp:TableRow>
                <asp:TableRow>
                    <asp:TableCell></asp:TableCell>
                    <asp:TableCell>
                        <asp:CustomValidator ID="IndicatorCustomValidator" runat="server" ValidateEmptyText="true" 
                            ErrorMessage="Select either an Output Indicator or a Process Indicator" ForeColor="Red"
                            OnServerValidate="IndicatorCustomValidator_ServerValidate" ValidationGroup="_plan">
                        </asp:CustomValidator>
                    </asp:TableCell>
                </asp:TableRow>
                </asp:Table>
                <asp:Button ID="SaveIndicatorBtn" runat="server" Text="Save" OnClick="SaveIndicatorBtn_Click" ValidationGroup="_plan" />
                <asp:Button ID="ReturnBtn" runat="server" Text="Return" OnClick="ReturnBtn_Click"  />
</asp:Content>
